
#ifndef _BSP__IMU_H
#define _BSP__IMU_H


#include "stm32f4xx_hal.h"
#include "ahrs.h"

#define MPU_IO_PROBE() //HAL_GPIO_TogglePin(IO_PROBE_GPIO_Port, IO_PROBE_Pin);
#define MPU6500_NSS_Low() HAL_GPIO_WritePin(GPIOF, GPIO_PIN_6, GPIO_PIN_RESET)
#define MPU6500_NSS_High() HAL_GPIO_WritePin(GPIOF, GPIO_PIN_6, GPIO_PIN_SET)
#define MPU_DELAY(x) HAL_Delay(x)

#define MPU_HSPI hspi5
//#define MPU_NSS_LOW() HAL_GPIO_WritePin(GPIOF, SPI5_NSS_Pin, GPIO_PIN_RESET)
//#define MPU_NSS_HIGH() HAL_GPIO_WritePin(GPIOF, SPI5_NSS_Pin, GPIO_PIN_SET)
#define IST_ENABLE() HAL_GPIO_WritePin(GPIOE, GPIO_PIN_2, GPIO_PIN_SET)

#define MPU6500_ID                  (0x70)

struct mpu_calibrate
{
  uint8_t gyro_flag;
  uint8_t acc_flag;
  uint8_t mag_flag;
};

struct mpu_data_info
{
  int16_t ax;
  int16_t ay;
  int16_t az;

  int16_t gx;
  int16_t gy;
  int16_t gz;

  int16_t mx;
  int16_t my;
  int16_t mz;

  int16_t temp;

  int16_t ax_offset;
  int16_t ay_offset;
  int16_t az_offset;

  int16_t gx_offset;
  int16_t gy_offset;
  int16_t gz_offset;

  int16_t mx_offset;
  int16_t my_offset;
  int16_t mz_offset;
};





uint8_t MPU6500_Init(void);
uint8_t MPU6500_Write_Reg(uint8_t const reg, uint8_t const data);
uint8_t MPU6500_Read_Reg(uint8_t const reg);
uint8_t MPU6500_Read_Regs(uint8_t const regAddr, uint8_t *pData, uint8_t len);
void IMU_Get_Data(struct ahrs_sensor *sensor);
uint8_t IST8310_Init(void);


#endif
